package com.rem.springboot1.controller;

import com.rem.springboot1.pojo.User;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;


/**
 * @author Rem
 * @date 2021/5/26
 */
@RestController
@RequestMapping("/")
public class TestController {


    @PostMapping("/test")
    String hello(@RequestBody @Valid User user, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return bindingResult.getFieldError().getDefaultMessage();
        }
        return "ok";
    }
}